package com.euc.springbootframework.auth.service;

import com.euc.springbootframework.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.Collections;

@Service("UserDetailsService")
public class UserDetailServiceImpl implements UserDetailsService{

    @Autowired
    private UserDao userDao;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        User object = null;
        com.euc.springbootframework.entity.User user = userDao.findByUsername(username);
        if(user!=null){
            object = new User(user.getUsername(),user.getPassword(), Collections.emptyList());
        }
        System.out.println(object.toString());
        return object;
    }
}
